home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11503 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.8 KB  |  100 lines

  1. Path: fido.asd.sgi.com!news
  2. From: Emmanuel Mogenet <mgix@aw.sgi.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: C++ Shortcomings ?
  5. Date: Thu, 14 Mar 1996 13:24:29 -0800
  6. Organization: Alias/Wavefront
  7. Message-ID: <31488E8D.167E@aw.sgi.com>
  8. NNTP-Posting-Host: mgixppp.sb.aw.sgi.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (X11; I; IRIX 5.3 IP22)
  13.  
  14. Here are two questions about C++
  15.  
  16. 1. Class dependent private interfaces.
  17. ---------------------------------------
  18. One thing I'd love to be able to do in C++ is the following thing:
  19.  
  20. class ManagerForClassA
  21. {
  22. public:
  23.         ManagerForClassA();
  24.         ~ManagerForClassA();
  25. private:
  26.         ...
  27. };
  28.  
  29. class ClassASpecialClient
  30. {
  31. public:
  32.         ClassASpecialClient();
  33.         ~ClassASpecialClient();
  34. private:
  35.         ...
  36. }
  37.  
  38. class A
  39. {
  40. public:
  41.         A();
  42.         ~A();
  43.  
  44. restricted ManagerForClassA:
  45.         void    SomeMethodOnlyCallableOnlyByManagerForClassA();
  46.  
  47. restricted ClassASpecialClient:
  48.         void    SomeMethodOnlyCallableOnlyByClassASpecialClient();
  49.  
  50. restricted ClassASpecialClient ManagerForClassA:
  51.         void    SomeMethodOnlyCallableByBoth();
  52. }
  53.  
  54. In other word, make portions of the interface to a class private to
  55. only some classes.
  56.  
  57.         1. Wouldn't that be nicer than the friend mechanism that cracks
  58.            open a class a spill its guts ?
  59.         2. Is there a clean way to achieve in today's C++ standard ?
  60.         3. Or is it a bad idea altogether ?
  61.  
  62. 2. Pointer type manipulation
  63. -----------------------------
  64.  
  65. A very disappointing thing in C++ (unless I am mistaken and it is actually
  66. possible to do so) is the following situation:
  67.  
  68. If A is a class, then most operations on A can be redefined.
  69. Because A is a full blown type.
  70.  
  71. Sadly, the same can not be said about A* (type: pointer to A).
  72.  
  73. Even though A* is a type, none of its default manipulations
  74. can be redefined.
  75.  
  76. Example: You can tell C++, that you want to gain control of the
  77. situation whenever an object of type A is duplicated.
  78.  
  79. You do so by redefining the default copy constructor and the default
  80. assignment operator.
  81.  
  82. But can you tell C++ that you want to gain control whenever a pointer of
  83. A* is duplicated ? Why can't I redefine the copy constructor for the type A* ?
  84.  
  85. In my way of looking at thing, that'd be a *great* way of doing clean reference
  86. counting, instead of half-baked method using a redefinition of operator->.
  87.  
  88. Comments ?
  89.  
  90.         - Mgix
  91. ________________________________________________________________________________
  92. Emmanuel Mogenet <mgix@aw.sgi.com>                            PGP Key on Request
  93. Home Page: http://reality.sgi.com/mgix
  94.  
  95.   "Any man who cannot explain his work to a fourteen year old is a charlatan."
  96.  
  97.                 -- Jons Jacob Berzelius
  98.  
  99. ________________________________________________________________________________
  100.